package com.goldenautumn.prefabricate.business.mall

import com.goldenautumn.prefabricate.business.entity.AddCarGoodsParams
import com.goldenautumn.prefabricate.business.entity.BasicPage
import com.goldenautumn.prefabricate.business.entity.CarDataList
import com.goldenautumn.prefabricate.business.entity.GoodsDetailsReq
import com.goldenautumn.prefabricate.business.entity.GoodsInfoVO
import com.goldenautumn.prefabricate.business.entity.HomeDataVo
import com.goldenautumn.prefabricate.business.entity.HomeTabVo
import com.goldenautumn.prefabricate.business.entity.SearchParams
import com.goldenautumn.prefabricate.business.entity.TypeGoodsResp
import com.goldenautumn.prefabricate.business.entity.TypeInfoVo
import com.goldenautumn.prefabricate.business.service.MallService
import com.goldenautumn.prefabricate.utils.getToken
import com.goldenautumn.prefabricate.utils.objectToMap
import qncx.external.common.network.SimpleRepository

class MallRepositoryImpl  : SimpleRepository() {

    suspend fun getHomeData() : HomeDataVo {
        var map = HashMap<String,Any>()
        map["s"] = "api/page/index"
        return getService(MallService::class.java).getHomeData(map)
    }

    suspend fun getHomeTab() : List<HomeTabVo> {
        var map = HashMap<String,Any>()
        map["s"] = "api/page/brand"
        return getService(MallService::class.java).onTabList(map)
    }

    suspend fun getGoodsList(params:SearchParams) : BasicPage<GoodsInfoVO> {
        var map = HashMap<String,Any>()
        map["s"] = "api/goods/lists"
        map["token"] = getToken()
        if(params.categoryID != null) map["category_id"] = "${params.categoryID}"
        if(params.search != null) map["search"] = "${params.search}"
        if(params.sortType != null) map["sortType"] = "${params.sortType}"
        if(params.sortPrice != null) map["sortPrice"] = "${params.sortPrice}"
        if(params.isSpecial != null) map["${params.isSpecial}"] = "1"
        return getService(MallService::class.java).getGoodsList(map)
    }

    suspend fun getGoodsDetails(id: String) : GoodsDetailsReq {
        var map = HashMap<String,Any>()
        map["s"] = "api/goods/detail"
        map["token"] = getToken()
        map["goods_id"] = id
        return getService(MallService::class.java).getGoodsDetails(map)
    }

    suspend fun onAddVarGoods(params: AddCarGoodsParams) : Any {
        return getService(MallService::class.java).addCarGoods(params.objectToMap(),params)
    }

    suspend fun subCarGoods(params: AddCarGoodsParams) : Any {
        return getService(MallService::class.java).subCarGoods(params.objectToMap(),params)
    }

    suspend fun getCarList() : CarDataList {
        var map = HashMap<String,Any>()
        map["s"] = "api/cart/lists"
        map["token"] = getToken()
        return getService(MallService::class.java).getCarList(map)
    }

    suspend fun deleteCarData(skuID:String) : Any {
        var map = HashMap<String,Any>()
        map["s"] = "api/cart/delete"
        map["token"] = getToken()
        map["goods_sku_id"] = skuID
        return getService(MallService::class.java).deleteCarData(map,map)
    }

    suspend fun getCategoryList() : TypeGoodsResp {
        var map = HashMap<String,Any>()
        map["s"] = "api/category/index"
        map["token"] = getToken()
        return getService(MallService::class.java).categoryList(map)
    }



}